package sssta.org.picassodemo;

/**
 * Created by cauchywei on 15/4/18.
 */

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;


/**
 * Created by cauchywei on 15/3/11.
 */
public class StudentAdapter extends RecyclerView.Adapter {


    private List<String> mStudentIds;
    private LayoutInflater mInflater;
    private Context mContext;

    public class StudentViewHolder extends RecyclerView.ViewHolder {

        public TextView studentId;
        public ImageView photo;

        public StudentViewHolder(final View item) {
            super(item);
            studentId = (TextView) item.findViewById(R.id.student_id);
            photo = (ImageView) item.findViewById(R.id.photo);
        }
    }

    public StudentAdapter(Context context, List<String> studentIds) {
        this.mStudentIds = studentIds;
        mInflater = LayoutInflater.from(context);
        mContext = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mInflater.inflate(R.layout.item_photo, parent, false);
        return new StudentViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        StudentViewHolder viewHolder = (StudentViewHolder) holder;

        String id = mStudentIds.get(position);

        viewHolder.studentId.setText(id);

        Picasso.with(mContext)
                .load("http://my.xidian.edu.cn/ph/"+id+".jpg")
                .into(viewHolder.photo);

    }

    @Override
    public int getItemCount() {
        return mStudentIds.size();
    }


}
